using UnityEngine;

public class SceneController : MonoBehaviour
{
	public static SceneController instance;

	public Transform IslandTra;

	public GameObject speedeffectobj;

	private GameObject tempobj;

	public Transform bigisland;

	public Transform smallisland;

	private JDController tempjd;

	private islandcon tempisland;

	private GameLevel curlevel;

	private string[] playernames = new string[10]
	{
		"F4",
		"JAS39",
		"SU34",
		"Mirage2000",
		"LCA",
		"F15",
		"J20",
		"T50",
		"F22",
		"F35"
	};

	public PlayerAtt playeratt;

	public ctl_att[] playerCtlatt;

	public GameChaInfo curGCinfo;

	private int gamefirst;

	public bool isblue;

	public Material sky1;

	public Material sky2;

	public MeshRenderer watermesh;

	public Material water1;

	public Material water2;

	public Light mainlight;

	private void Awake()
	{
		if (instance == null)
		{
			instance = this;
		}
		playeratt = GlobalInf.CurPlayerAtt;
		Application.targetFrameRate = 0;
		GlobalInf.flyrange_AI = 4000;
		gamefirst = PlayerPrefs.GetInt("gamefirst", 1);
		if (gamefirst == 1)
		{
			if (GlobalInf.gamemode == TASKMODE.level && GlobalInf.CurrentLevel == 0)
			{
				GlobalInf.gamefirst = true;
				if (GlobalInf.isinverty)
				{
					PlayerPrefs.SetInt("isinverty", 0);
					GlobalInf.isinverty = false;
				}
				if (GlobalInf.PlaneCtrlType == PLANECTRLTYPE.GRAVITY)
				{
					GlobalInf.PlaneCtrlType = PLANECTRLTYPE.BUTTON;
					PlayerPrefs.SetInt("controltype", 0);
				}
			}
		}
		else
		{
			GlobalInf.gamefirst = false;
		}
		environmentSet();
	}

	private void Start()
	{
		CreatPlayer();
		if (GlobalInf.gamemode == TASKMODE.level)
		{
			curlevel = DataController.instance.DataLevel[GlobalInf.CurrentLevel];
			init_island(curlevel.island);
			init_jidi(curlevel.jidi1id);
			init_jidi(curlevel.jidi2id);
			GlobalInf.centerpoint = curlevel.center;
			PlaneMoveController.instance.init_posrot(curlevel.start_pr);
			return;
		}
		switch (GlobalInf.chanllengeid)
		{
			case 6:
				curGCinfo = DataController.instance.surdata[GlobalInf.chanllenge_mode].gcinfo;
				break;
			case 7:
				curGCinfo = DataController.instance.tdmdata[GlobalInf.chanllenge_mode].gcinfo;
				break;
			case 8:
				curGCinfo = DataController.instance.dtbdata[GlobalInf.chanllenge_mode].gcinfo;
				break;
			case 9:
				curGCinfo = DataController.instance.ffadata[GlobalInf.chanllenge_mode].gcinfo;
				break;
		}
		init_island(curGCinfo.island);
		init_jidi(curGCinfo.jidi1id);
		init_jidi(curGCinfo.jidi2id);
		GlobalInf.centerpoint = curGCinfo.center;
		PlaneMoveController.instance.init_posrot(curGCinfo.start_pr);
	}

	public void CreatPlayer()
	{
		PlaneMoveController.instance.initinfo(playerCtlatt[GlobalInf.CurPlayerAtt.planeindex]);
		tempobj = (UnityEngine.Object.Instantiate(Resources.Load("Player/" + playernames[GlobalInf.CurPlayerAtt.planeindex])) as GameObject);
		plane_smothfollow component = tempobj.GetComponent<plane_smothfollow>();
		component.init_plane();
		tempobj = (UnityEngine.Object.Instantiate(speedeffectobj) as GameObject);
		component.set_speedeffect(tempobj);
	}

	public void init_island(int islandtype)
	{
		switch (islandtype)
		{
			case -1:
				return;
			case 0:
				tempobj = (UnityEngine.Object.Instantiate(Resources.Load("Island/bigisland_single")) as GameObject);
				break;
			case 1:
				tempobj = (UnityEngine.Object.Instantiate(Resources.Load("Island/qundao_single")) as GameObject);
				break;
			case 2:
				tempobj = (UnityEngine.Object.Instantiate(Resources.Load("Island/island_double")) as GameObject);
				break;
		}
		tempobj.transform.parent = IslandTra;
		tempisland = tempobj.GetComponent<islandcon>();
		bigisland = tempisland.big;
		smallisland = tempisland.small;
		if (GlobalInf.CurrentQuality >= Quality.Low && (islandtype == 0 || islandtype == 2))
		{
			tempobj = (UnityEngine.Object.Instantiate(Resources.Load("Island/bigisland_objs")) as GameObject);
			tempobj.transform.parent = bigisland;
			tempobj.transform.localPosition = Vector3.zero;
			tempobj.transform.localRotation = Quaternion.Euler(Vector3.zero);
		}
	}

	public void init_jidi(int jdtype)
	{
		if (jdtype != -1 && GlobalInf.CurrentQuality >= Quality.Low)
		{
			switch (jdtype)
			{
				case 0:
					tempobj = (UnityEngine.Object.Instantiate(Resources.Load("JD/AI_JD_1")) as GameObject);
					tempobj.transform.parent = bigisland;
					break;
				case 1:
					tempobj = (UnityEngine.Object.Instantiate(Resources.Load("JD/AI_JD_2")) as GameObject);
					tempobj.transform.parent = bigisland;
					break;
				case 2:
					tempobj = (UnityEngine.Object.Instantiate(Resources.Load("JD/Fri_JD_1")) as GameObject);
					tempobj.transform.parent = bigisland;
					break;
				case 3:
					tempobj = (UnityEngine.Object.Instantiate(Resources.Load("JD/Fri_JD_2")) as GameObject);
					tempobj.transform.parent = bigisland;
					break;
				case 4:
					tempobj = (UnityEngine.Object.Instantiate(Resources.Load("JD/AI_JD_3")) as GameObject);
					tempobj.transform.parent = smallisland;
					break;
				case 5:
					tempobj = (UnityEngine.Object.Instantiate(Resources.Load("JD/AI_JD_4")) as GameObject);
					tempobj.transform.parent = smallisland;
					break;
			}
			tempjd = tempobj.GetComponent<JDController>();
			tempjd.setpos();
		}
	}

	private void OnDestroy()
	{
		if (instance != null)
		{
			instance = null;
		}
	}

	public void environmentSet()
	{
		if (GlobalInf.gamefirst)
		{
			isblue = true;
		}
		else if (UnityEngine.Random.Range(0, 3) > 1)
		{
			isblue = false;
		}
		else
		{
			isblue = true;
		}
		if (isblue)
		{
			RenderSettings.skybox = sky1;
			RenderSettings.fogColor = new Color(212f / 255f, 218f / 255f, 46f / 51f);
			RenderSettings.fogStartDistance = 5000f;
			watermesh.sharedMaterial = water1;
			mainlight.color = Color.white;
			if (GlobalInf.CurrentQuality > (Quality)101)
			{
				tempobj = (UnityEngine.Object.Instantiate(Resources.Load("obj/sun")) as GameObject);
			}
		}
		else
		{
			RenderSettings.skybox = sky2;
			RenderSettings.fogColor = new Color(25f / 51f, 133f / 255f, 0.5882353f);
			watermesh.sharedMaterial = water2;
			RenderSettings.fogStartDistance = 3500f;
			mainlight.color = new Color(181f / 255f, 194f / 255f, 226f / 255f);
		}
	}
}
